package temp3;

import java.io.IOException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Reducer;

public class ReceiverCountReducer extends Reducer<Text, Text, Text, LongWritable> {
    
    private LongWritable result = new LongWritable();
    private long totalReceivers = 0;
    
    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) 
            throws IOException, InterruptedException {
        // 每个唯一的key就是一个接收人，只需计数
        totalReceivers++;
    }
    
    @Override
    protected void cleanup(Context context) 
            throws IOException, InterruptedException {
        // 在所有reduce完成后输出总数
        result.set(totalReceivers);
        context.write(new Text("Total unique receivers"), result);
    }
}